using System;

namespace OrderSystem.SystemFramework
{
	public static class CommonMethod
	{
		public static string PadSpaceOnRight(string s, int nTotalWidth)
		{
			int num = 0;
			for (int i = 0; i < s.Length; i++)
			{
				if (Convert.ToInt32(s[i]) > 255)
				{
					num += 2;
				}
				else
				{
					num++;
				}
			}
			int num2 = nTotalWidth - num;
			if (num2 > 0)
			{
				for (int i = 0; i < num2; i++)
				{
					s += ' ';
				}
			}
			return s;
		}

		public static int GetNumberOfBytes(string sData)
		{
			int num = 0;
			for (int i = 0; i < sData.Length; i++)
			{
				if (Convert.ToInt32(sData[i]) > 255)
				{
					num += 2;
				}
				else
				{
					num++;
				}
			}
			return num;
		}

		public static string Fun1(string sDate)
		{
			string result;
			if (sDate == null)
			{
				result = null;
			}
			else
			{
				string text = "";
				for (int i = 0; i < sDate.Length; i++)
				{
					if (sDate[i] >= '０' && sDate[i] <= '９')
					{
						text += sDate[i] - 'ﻠ';
					}
					else if (sDate[i] == '。' || sDate[i] == '．')
					{
						text += '.';
					}
					else
					{
						text += sDate[i];
					}
				}
				result = text;
			}
			return result;
		}

		public static string MoneyToUpper(decimal mJE)
		{
			string result;
			if (mJE == 0m)
			{
				result = "零元整";
			}
			else
			{
				string text = mJE.ToString("####.00");
				if (text.Length > 15)
				{
					result = "";
				}
				else
				{
					text = new string('0', 15 - text.Length) + text;
					string str = text.Substring(0, 4);
					string str2 = text.Substring(4, 4);
					string str3 = text.Substring(8, 4);
					string text2 = text.Substring(13, 2);
					string text3 = CommonMethod.getupper(str, "亿");
					string text4 = CommonMethod.getupper(str2, "万");
					string text5 = CommonMethod.getupper(str3, "元");
					string text6 = "";
					string text7 = "";
					if (text[3] == '0' || text[4] == '0')
					{
						text6 = "零";
					}
					if (text[7] == '0' || text[8] == '0')
					{
						text7 = "零";
					}
					string text8 = string.Concat(new string[]
					{
						text3,
						text6,
						text4,
						text7,
						text5
					});
					for (int i = 0; i < text8.Length; i++)
					{
						if (text8[i] != '零')
						{
							text8 = text8.Substring(i);
							break;
						}
					}
					for (int i = text8.Length - 1; i > -1; i--)
					{
						if (text8[i] != '零')
						{
							text8 = text8.Substring(0, i + 1);
							break;
						}
					}
					if (text8 == new string('零', text8.Length))
					{
						text8 = "";
					}
					else if (text8[text8.Length - 1] != '元')
					{
						text8 += "元";
					}
					if (text2 == "00")
					{
						text8 += "整";
					}
					else
					{
						string text9 = CommonMethod.getint(text2[0]);
						if (text9 == "零")
						{
							text8 += text9;
						}
						else
						{
							text8 = text8 + text9 + "角";
						}
						text9 = CommonMethod.getint(text2[1]);
						if (text9 == "零")
						{
							text8 += "整";
						}
						else
						{
							text8 = text8 + text9 + "分";
						}
					}
					if (text8[0] == '零')
					{
						text8 = text8.Substring(1);
					}
					result = text8;
				}
			}
			return result;
		}

		private static string getupper(string str, string sUnit)
		{
			string result;
			if (str == "0000")
			{
				result = "";
			}
			else
			{
				string text = "";
				string text2 = CommonMethod.getint(str[0]);
				string text3 = CommonMethod.getint(str[1]);
				string text4 = CommonMethod.getint(str[2]);
				string text5 = CommonMethod.getint(str[3]);
				if (text2 != "零")
				{
					text = text + text2 + "仟";
				}
				else
				{
					text += text2;
				}
				if (text3 != "零")
				{
					text = text + text3 + "佰";
				}
				else if (text2 != "零")
				{
					text += text3;
				}
				if (text4 != "零")
				{
					text = text + text4 + "拾";
				}
				else if (text3 != "零")
				{
					text += text4;
				}
				if (text5 != "零")
				{
					text += text5;
				}
				if (text[0] == '零')
				{
					text = text.Substring(1);
				}
				if (text[text.Length - 1] == '零')
				{
					text = text.Substring(0, text.Length - 1);
				}
				result = text + sUnit;
			}
			return result;
		}

		private static string getint(char c)
		{
			string result = "";
			switch (c)
			{
			case '0':
				result = "零";
				break;
			case '1':
				result = "壹";
				break;
			case '2':
				result = "贰";
				break;
			case '3':
				result = "叁";
				break;
			case '4':
				result = "肆";
				break;
			case '5':
				result = "伍";
				break;
			case '6':
				result = "陆";
				break;
			case '7':
				result = "柒";
				break;
			case '8':
				result = "捌";
				break;
			case '9':
				result = "玖";
				break;
			}
			return result;
		}
	}
}
